//
//  Transfers.h
//  SolarSeek
//
//  Created by Erick Fejta on 05/01/26.
//  Copyright 2005 Erick Fejta. All rights reserved.
//

#import <Cocoa/Cocoa.h>

@class Peer;
@class Share;
@class SharePeer;

#import "EnumTypes.h"

@interface Transfer : NSObject {
	BOOL _active;
	NSDate *_dateStarted;
	NSDate *_dateActiveLast;
	NSString *_descriptionState;
	NSFileHandle *_fileHandle;
	Peer *_peerForTransfer;
	NSTimeInterval _secondsTransferred;
	Share *_share;
	TransferState _state;
	unsigned _token;
	unsigned _tokenPeerChosen;
	unsigned _locationQueue;
}

- (id)initWithPeer:(Peer *)peer token:(unsigned)token share:(Share *)share;
- (NSComparisonResult)compare:(Transfer *)other;

- (unsigned long long)countBytesRemaining;
- (unsigned long long)countBytesTotal;
- (NSDate *)dateFinished;
- (NSDate *)dateStarted;
- (NSString *)descriptionState;
- (Peer *)peer;
- (Share *)share;
- (double)speed;
- (TransferState)state;
- (NSTimeInterval)timeIntervalSpentTransferring;
- (NSTimeInterval)timeIntervalRemaining;
- (unsigned)token;
- (unsigned)tokenPeerChosen;
- (BOOL)transferring;

- (void)setState:(TransferState)state;
- (void)setState:(TransferState)state description:(NSString *)message;
- (void)setTokenPeerChosen:(unsigned)token;

- (void)closeBuffer;

- (unsigned)locationQueue;

- (void)setLocationQueue:(unsigned)location;

@end

@interface Transfer (Concrete)

- (unsigned long long)countBytesTransferred;
- (NSString *)filenameBuffer;
- (NSString *)filenameCurrent;
- (TransferType)type;
- (BOOL)openBuffer;

@end

@interface TransferUpload : Transfer {
	unsigned long long _transferred;
}

- (BOOL)seekToOffset:(unsigned long long)count;

- (NSData *)readData;	//readData* return 0 sized data if end of file
- (NSData *)readDataOfLength:(unsigned)countCeiling;

@end

@interface TransferDownload : Transfer {
	NSString *_filenameFinished;
	NSString *_filenameTemporary;
	NSFileManager *_fm;
}

- (id)initWithPeer:(Peer *)peer token:(unsigned)token share:(SharePeer *)share filenameTemporary:(NSString *)temporaryFilename filenameFinished:(NSString *)filenameFinished;

- (NSString *)filenameFinished;

- (void)writeData:(NSData *)data;	

@end

